<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@page
	import="b1w1nn1ng.crossf1t.gui.*,java.util.*,java.sql.*,b1w1nn1ng.crossf1t.business.*,b1w1nn1ng.crossf1t.db.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Profile</title>
<jsp:include page="/detectBrowser.jsp" />	
</head>
<body>

	<%
		User user;
		//In what is possibly the ugliest line of code ever, check if we set a friendID and if so,
		//view their page instead of the user's
		if (request.getParameter("friendID") != null)
			user = Database.getUserByID(Integer.parseInt((String) request
					.getParameter("friendID")));
		else
			user = (User) session.getAttribute("user");
		session.setAttribute("user", user);
	%>
	


	<div id="container">
		<jsp:include page="/navbar.jsp" />
		<h1>
			<%=user.getFirstName()%>'s Profile
		</h1>

		<hr />
		
		<%
			//only allow editing on your own page...
			if (request.getParameter("friendID") == null)
				out.println("<a href=\"profileEdit.jsp\" class=\"editProfileLink\"> Edit Profile </a>");
		%>
		
		<div style="clear:both"></div>

		<div id="formAlign">
		<table id="settingsTable">
			<tr>
				<td style="text-align:left;">Name: </td>
				<td style="text-align:left;"><%=user.getFirstName()%></td>
			</tr>
			<tr>
				<td style="text-align:left;" >Weight:</td>
				<td style="text-align:left;"><%=user.getWeight()%> pounds</td>
			</tr>
			<tr>
				<td style="text-align:left;">Height:</td>
				<td style="text-align:left;"><%=user.getHeight()%> inches</td>
			</tr>
				<tr>
					<td style="text-align:left;">BMI:</td>
					<td style="text-align:left;" ><%=user.calculateBMI()%> <%
 	double bmi = user.calculateBMI();
 	String output;
 	if (bmi < 16)
 		output = "Severely underweight";
 	else if (bmi < 18.5)
 		output = "Underweight";
 	else if (bmi < 25)
 		output = "Normal";
 	else if (bmi < 30)
 		output = "Overweight";
 	else if (bmi < 35)
 		output = "Obese Class I";
 	else if (bmi < 40)
 		output = "Obese Class II";
 	else
 		output = "Obese Class III";
 	out.print("(" + output + ")");
 %>

					</td>
				</tr>
				<tr>
					<td style="text-align:left;">Completed WODS:</td>
					<td style="text-align:left;"><%=user.getNumWorkouts()%></td>
				</tr>
				<tr>
					<td style="text-align:left;" >PR Info:</td>
					<td style="text-align:left;""><a href="calendarReset.jsp" id="calendarButton"> Calendar </a>
					</td>
				</tr>
			</table>


	</div>
</body>
</html>

